﻿//-----------------------------------------------------------------------
// <copyright file="ProjectsListEditor.xaml.cs" author="Artak Mkrtchyan">
//     Creative Commons - GNU General Public License (http://creativecommons.org/licenses/GPL/2.0/
// </copyright>
// <author>Artak Mkrtchyan</author>
// <email>mkArtak@gmail.com</email>
// <date>24/04/2013</date>
//-----------------------------------------------------------------------
using ConsoleHoster.Common.Utilities;
using ConsoleHoster.Common.Utilities.Threading;
using ConsoleHoster.ViewModel;
using System;
using System.Windows;

namespace ConsoleHoster.View.Popups
{
	/// <summary>
	/// Interaction logic for ProjectsListEditor.xaml
	/// </summary>
	public partial class ProjectsListEditor : Window
	{
		public ProjectsListEditor()
		{
			InitializeComponent();
		}

		public ProjectsListEditor(ProjectsListViewModel argViewModel, IDispatcher argDispatcher, ILogger argLogger)
			: this()
		{
			ValidationManager.RequireArgumentNotNull(argViewModel, "argViewModel");

			this.DataContext = argViewModel;
		}

		private void btnSave_Click(object sender, RoutedEventArgs e)
		{
			ProjectsListViewModel tmpVM = this.ViewModel;
			if (tmpVM.SelectedProject == null || tmpVM.SelectedProject.IsValid)
			{
				this.DialogResult = true;
			}
		}

		private void btnCancel_Click(object sender, RoutedEventArgs e)
		{
			this.DialogResult = false;
		}

		private void btnRemoveProject_Click(object sender, RoutedEventArgs e)
		{
			this.ViewModel.RemoveProject((sender as FrameworkElement).DataContext as ProjectDetailsViewModel);
		}

		public ProjectsListViewModel ViewModel
		{
			get
			{
				return this.DataContext as ProjectsListViewModel;
			}
		}
	}
}
